import java.io.File;
import java.util.*;

/**
 * Created by isoft-work 5 on 11/22/14.
 */
public class main {
   private static List<List<String>> L = new ArrayList<List<String>>();
   private static List<List<String>> R = new ArrayList<List<String>>();
   private static List<String> GT = new ArrayList<String>();

   public static void main(String[] args) {
      //      get path of project
      String path = System.getProperty("user.dir");
      readLuat(path);
      System.out.println("Nhập giả thuyết: \n");
      Scanner ob = new Scanner(System.in);
      String r = ob.nextLine();
      GT = getGT(r);
      Reason reason = new Reason(L, R,GT);
      List<String> result = reason.getGT();
   }

   private static void readLuat(String pathToFile) {
      try {
         Scanner sc = new Scanner(new File(pathToFile + "\\src\\main\\resources\\rule.txt"));
         while (sc.hasNext()){
            String s = sc.next();
            if (s.trim().isEmpty()) {
               break;
            }
            else {
               L.add(getLeft(s));
               R.add(getRight(s));
            }
         }
         sc.close();
      }
      catch (Exception ex) {
         System.out.print(ex);
      }
   }

   private static List<String> getLeft(String s) {
      List<String> r = new ArrayList<String>();
      String[] c = s.split("[|,^,-]");
      for(int i = 0; i < c.length - 1; i++) {
         r.add(c[i]);
      }
      return r;
   }

   private static List<String> getRight(String s) {
      List<String> r = new ArrayList<String>();
      String[] c = s.split("[|,->]");
      for(int i = 2; i < c.length; i++) {
         r.add(c[i]);
      }
      return r;
   }

   private static List<String> getGT(String s) {
      List<String> r = new ArrayList<String>();
      if(s.lastIndexOf("^") < 0) {
         r.add(s);
      }
      else {
         String[] c = s.split("[|,^]");
         for(int i = 0; i < c.length; i++) {
            r.add(c[i]);
         }
      }
      return r;
   }
}
